package com.zyb.config;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

//4.定义servlet容器的配置类
public class ServletContainersInitConfig extends
        AbstractDispatcherServletInitializer {
    //加载springMVC配置
    @Override
    protected WebApplicationContext createServletApplicationContext() {
    //初始化WebApplicationContext对象
        AnnotationConfigWebApplicationContext ctx = new
                AnnotationConfigWebApplicationContext();
    //加载指定配置类
        ctx.register(SpringMvcConfig.class);
        return ctx;
    }

    @Override
    //设置Tomcat接收的请求哪些归SpringMVC处理
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

    @Override
    //设置spring相关配置
    protected WebApplicationContext createRootApplicationContext() {
        return null;
    }
}

